function groups = groupsensors( house, maxsensors )

    thresholdTime=4;
    thresholdWeights=1;

    sensorid=house.ss(:,3);
    groupsweights=zeros(maxsensors,maxsensors);
    groups=zeros(maxsensors,maxsensors);

    for i=1:length(sensorid)
        currentTime=datevec(house.ss(i,1));
        currentSensorid=house.ss(i,3);
        groupsweights(currentSensorid,currentSensorid)=1000;
        groups(currentSensorid,currentSensorid)=currentSensorid;
        
        for k=i:length(sensorid)
            nextTime=datevec(house.ss(k,1));
            nextSensorid=house.ss(k,3);
            duration=nextTime-currentTime;
            duration(:,2)=duration(:,2)*30*24*60*60; % notice: february has less days
            duration(:,3)=duration(:,3)*24*60*60;
            duration(:,4)=duration(:,4)*60*60;
            duration(:,5)=duration(:,5)*60;
            duration=duration(:,2)+duration(:,3)+duration(:,4)+duration(:,5)+duration(:,6);        

            if duration<thresholdTime
               if currentSensorid ~= nextSensorid
                    groupsweights(currentSensorid,nextSensorid)=groupsweights(currentSensorid,nextSensorid)+1;
                    groupsweights(nextSensorid,currentSensorid)=groupsweights(nextSensorid,currentSensorid)+1;
                    groups(currentSensorid,nextSensorid)=nextSensorid;
                    groups(nextSensorid,currentSensorid)=currentSensorid;
               end
            else
               break;
            end 
        end
    end
    
    
    groupsweights=ceil(groupsweights/2);
    for i=1:(length(groupsweights)^2)
        if groupsweights(i) < thresholdWeights
            groups(i)=0;
        end
    end
    
    groups(~any(groups,2),:)=[];
    %groups=unique(groups,'rows');
    sortrows(groups);
end

